package com.ruicar.afs.cloud.bizcommon.business.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ruicar.afs.cloud.common.core.constant.CommonConstants;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @description: 融资费用申请表
 * @author: sijun.yu
 * @date: 2020/5/11 18:02
 */
@Data
@TableName(value = "fin_cost_details", autoResultMap = true)
@Accessors(chain = true)
public class FinCostDetails  {

    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.INPUT)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;
    /**
     * 申请编号
     */
    private String applyNo;
    /**
     * 车辆ID
     */
    private Long carId;
    /**
     * 融资费用类型;车款，附加贷
     */
    private String costType;
    /**
     * 算法类型
     */
    private String algorithmType;
    /**
     * 产品ID
     */
    private String productId;
    /**
     * 产品名称
     */
    private String productName;
    /**
     * 合同金额
     */
    private BigDecimal contractAmt;
    /**
     * 贷款期限
     */
    private Integer loanTerm;
    /**
     * 客户利率/贴息后利率
     */
    private BigDecimal custRate;
    /**
     * 结算利率
     */
    private BigDecimal settleRate;
    /**
     * 上调/下调
     */
    private String adjustType;
    /**
     * 调整基点
     */
    private Integer basicPoint;
    /**
     * 首付比例
     */
    private BigDecimal downPayScale;
    /**
     * 首付金额
     */
    private BigDecimal downPayAmt;
    /**
     * 是否尾款
     */
    private String isTail;
    /**
     * 尾付比例
     */
    private BigDecimal tailPayScale;
    /**
     * 尾付金额
     */
    private BigDecimal tailPayAmt;
    /**
     * 贴息方式
     */
    private String discountType;
    /**
     * 贴息总额
     */
    private BigDecimal discountAmt;
    /**
     * 厂商最大贴息额
     */
    private BigDecimal maxDiscountAmt;
    /**
     * 贷款金额
     */
    private BigDecimal loanAmt;
    /**
     * 利息总额
     */
    private BigDecimal totalInterest;
    /**
     * 租金总额
     */
    private BigDecimal totalRent;
    /**
     * 月供金额
     */
    private BigDecimal monthPayAmt;
    /**
     * 是否有子产品
     **/
    private String isSubProduct;
    /**
     * 附加贷金额
     **/
    private BigDecimal addAmt;
    /**
     * 还款方式
     */
    private String repaymentMethod;
    /**
     * 补贴利率
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "补贴利率")
    private BigDecimal discountRate;

    public BigDecimal getDiscountRate(){
        if(settleRate!=null && custRate!=null){
            this.discountRate=settleRate.subtract(custRate).setScale(2,BigDecimal.ROUND_HALF_UP);
            return discountRate;
        }
        return BigDecimal.ZERO;
    }
    /**
     * 创建人
     */
    @TableField(fill = FieldFill.INSERT)
    private String createBy;
    /**
     * 创建时间
     */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /**
     * 更新人
     */
    @TableField(fill = FieldFill.UPDATE)
    private String updateBy;
    /**
     * 更新时间
     */
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.UPDATE)
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;
    /**
     * 删除标记
     */
    @TableLogic
    private String delFlag = CommonConstants.STATUS_NORMAL;
    /**
     * 客户费率（月）
     */
    @TableField(exist = false)
    private BigDecimal monthlyRate;
    /**
     * 万元系数法
     */
    @TableField(exist = false)
    private BigDecimal myriadCoefficient;

}
